package util;

import java.sql.*;
public class DBConn {
    public static final String DriverName="com.mysql.cj.jdbc.Driver";
    public static final String URL="jdbc:mysql://localhost:3306/student?useSSL=false&serverTimezone=UTC";
    public static final String USER = "root";
    public static final String PWD = "123456";
    //加载数据库驱动
    static {
        try {
            Class.forName(DriverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    //进行链接
    public static Connection getConn()
    {
        Connection conn=null;
        try {
            conn = DriverManager.getConnection(URL, USER, PWD);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return conn;
    }
//关闭

    /**
     *
     * @param conn
     * @param pre
     * @param rs
     */
    public static void close(Connection conn, PreparedStatement pre, ResultSet rs)
    {
        try {
            if(conn!=null)
            {
                conn.close();
            }
            if(pre!=null)
            {
                pre.close();
            }
            if(rs!=null)
            {
                rs.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}